#include <stdio.h>
#include <omp.h>
//编译指令
//gcc -std=c99 -fopenmp 8Lock.c -o cmake-build/8Lock && export OMP_NUM_THREADS=512 && time ./cmake-build/8Lock

int main()
{
    
    {
        long long         sum=0;
        static omp_lock_t lock;
        omp_init_lock(&lock);
        #pragma omp parallel for shared(lock,sum) default(none)
        for(int i=0;i<1000;++i)
        {
            omp_set_lock(&lock);
            sum+=i;
            omp_unset_lock(&lock);
        }
        omp_destroy_lock(&lock);
        printf("%lld\n",sum);
    }
    {
        long long sum=0;
        #pragma omp parallel for shared(sum) default(none)
        for(int i=0;i<1000;++i)
            sum+=i;
        printf("%lld\n",sum);
    }
    return 0;
}
